<?php
namespace app\protocol\commands;

class IncrCommand extends BaseCommand
{
    public function execute($params, $connection): string
    {
        $args = $this->parseParams($params);
        $this->validateArgumentCount($args, 1, self::getUsage());

        $x = $this->validateNumeric($args[0], '参数');

        $result = $x + 1;

        return $result == (int)$result ? (string)(int)$result : (string)$result;
    }

    public static function getDescription(): string
    {
        return '自增运算: incr <x>';
    }

    public static function getUsage(): string
    {
        return 'incr 10';
    }
}